/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package poker.game;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author cbowman
 */
public class MinimaxOLD {

   private int pocket_pair;
   private int connectors;
   private int suited;
   private int[] encoding;
   private int[] difference;
   private int p1_chips;
   private int p2_chips;
   private int[] decisions_1 = {0,2,3};
   private int[] decisions_2 = {1,3};
   private int[] decisions_3 = {0,2};


   public MinimaxOLD(int pp, int c, int s, int[] e, int[] d, int pc1, int pc2){
       pocket_pair = pp;
       connectors = c;
       suited = s;
       encoding = e;
       difference = d;
       p1_chips = pc1;
       p2_chips = pc2;
   }

   

   public int minmax(int preDec, int round, int turn, int pchips1, int pchips2){
        List<Integer> decisions = getDecisions(preDec, round, pchips1, pchips2);
        List<Integer> vals = new ArrayList<Integer>();
        int val = -3;
        for(Integer i : decisions){
            int dec = i;
            if(dec == 3){
                if(pchips1 < pchips2){
                    vals.add(minmax(dec, round, turn + 1, pchips2 + 20, pchips2));
                }
                if(pchips1 >= pchips2){
                    vals.add(minmax(dec, round, turn + 1, pchips1, pchips1 + 20));
                }
            }
            if(dec == 2){
                if(pchips1 < pchips2){
                    vals.add(minmax(dec, round, turn + 1, pchips2, pchips2));
                }
                if(pchips1 > pchips2){
                    vals.add(minmax(dec, round, turn + 1, pchips1, pchips1));
                }
            }
            if(dec == 0){
                vals.add(minmax(dec, round, turn + 1, pchips1, pchips2));
            }
            if(dec == 1){
                vals.add(minmax(dec, round, turn + 1, pchips1, pchips2));
            }
            if(dec == -1){
                //evaluate function
                if(turn == 1)
                    vals.add(-25);
                if(turn == 2)
                    vals.add(-15);
                if(turn == 3)
                    vals.add(-5);
                if(turn == 4)
                    vals.add(5);
                if(turn == 5)
                    vals.add(15);
            }
        }
        val = vals.get(0);
        for(Integer i : vals){
            if((turn % 2) == 0){
                if(i.intValue() > val)
                    val = i.intValue();
            }
            else{
                if(i.intValue() < val)
                    val = i.intValue();
            }
        }
        System.out.println("Turn: " + turn + ", Value: " + val);
        return val;
   }

   //   0 => fold
   //   1 => check
   //   2 => call
   //   3 => raise
   //  -1 => evaluate function in next step
   //  -2 => start of round

   public List<Integer> getDecisions(int preDec, int round, int pchips1, int pchips2){
       List<Integer> decisions = new ArrayList<Integer>();
       if(round == 1){
           if(preDec == -2){
               decisions.add(0); decisions.add(2); decisions.add(3);
           }
           if(preDec == 3){
               if((pchips1 != 80) && (pchips2 != 80)){
                   decisions.add(0); decisions.add(2); decisions.add(3);
               }
               else{
                   decisions.add(0); decisions.add(2);
               }
           }
           if(preDec == 0){
               decisions.add(-1);
           }
           if(preDec == 1){
               decisions.add(-1);
           }
           if(preDec == 2){
               if(pchips1 != 20){
                   decisions.add(-1);
               }
               else{
                   decisions.add(1); decisions.add(3);
               }
           }
       }
       else{
           if(preDec == -2){
               decisions.add(1); decisions.add(3);
           }
           if(preDec == 3){
               if((pchips1 != 80) && (pchips2 != 80)){
                   decisions.add(0); decisions.add(2); decisions.add(3);
               }
               else{
                   decisions.add(0); decisions.add(2);
               }
           }
           if(preDec == 0){
               decisions.add(-1);
           }
           if(preDec == 2){
               decisions.add(-1);
           }
           if(preDec == 1){
               decisions.add(1); decisions.add(3);
           }
       }
       return decisions;
   }
}
